package com.hvtt.web.controllerUtils;

import com.hvtt.web.utilities.Utilities;
import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

/**
 * Navigation info.
 *
 * @author Nguyễn Hoàng Danh
 */
@ManagedBean
@SessionScoped
public class NavigationContext implements Serializable {

    public String getMenuitemStyleClass(final String page) {
        final String viewId = Utilities.getRequest().getParameter("menu_id");
        if (viewId != null && viewId.equals(page)) {
            return "ui-state-active";
        }

        return "";
    }

    public String getMenuTopStyleClass(final String page, boolean haschild) {
        final String viewId = getViewId();
        if (viewId != null && viewId.contains(page)) {
            if (haschild) {
                return "active1";
            } else {
                return "active";
            }
        }
        return "";
    }

    public String getViewId() {
        FacesContext fc = FacesContext.getCurrentInstance();
        String viewId = fc.getViewRoot().getViewId();
        String selectedComponent;
        if (viewId != null) {
            selectedComponent = viewId.substring(viewId.lastIndexOf("/") + 1, viewId.lastIndexOf("."));
        } else {
            selectedComponent = null;
        }

        return selectedComponent;
    }
}
